package com.mxprojects.io
{
	import com.mxprojects.gui.DefaultDialog;
	import com.mxprojects.language.Language;
	import com.mxprojects.language.Word;
	import com.mxprojects.views.Forums;
	import com.mxprojects.views.Posts;
	import com.mxprojects.views.Threads;
	
	public class Permissions
	{	
		public static var isAdmin:int;
		public static var isModerator:int;
		public static var isAllowedToPost:int;
		
		public static function setup(adminPermission:int, moderatorPermission:int, postPermission:int):void {
			//this will allow things to be carried over from threads, to posts
			isAdmin = adminPermission;
			isModerator = moderatorPermission;
			isAllowedToPost = postPermission;
			
			//check the location and do what you need to do
			check();
		}
		
		private static function check():void {
			//this function will take the current location and light up 
			//anything that the user may or may not be able to do
			
			//figure out where we are and act
			switch(MXP3.currentLocation){
				case Word.REGISTER:
				case Word.FORUMS:
					//if it's the forums then we just force a reload
					Forums.load();
				break;
				
				case Word.THREADS:
					//see if we are able to make a new post
					if(Threads.isForumRestricted == 0 && isAllowedToPost == 1 || isAdmin == 1 || isModerator == 1){
						Threads.setNewThreadButton(true);
					}
				break;
				
				case Word.POSTS:
					//handle the posts section
					if(Threads.isForumRestricted == 0 && isAllowedToPost == 1 || isAdmin == 1 || isModerator == 1){
						Posts.setNewThreadButton(true);
					}
					
					if(Posts.isReadOnly == 0 && isAllowedToPost == 1 || isAdmin == 1 || isModerator == 1){
						Posts.setReplyPostButton(true);
						Posts.setPostOptions(true);
					}
				break;
			}
		}
		
		public static function error():void {
			//throw up an error about not having permissions
			DefaultDialog.show(Language.main(Word.ERROR_PERMISSION_DENIED), true, Word.ERROR, returnToHome);
		}
		
		public static function returnToHome():void {
			//send the user back home because the permissions failed
			DeepLinking.setLink(Word.FORUMS, DeepLinking.createLinkArray());
		}

	}
}